<?php
session_start();

if (isset($_SESSION['ID'])) {
    $ID_LOGADO = $_SESSION['ID'];
    $PERMISSAO = $_SESSION['PERMISSAO'];
} else {
    echo "<script type='text/javascript'>";
    echo "window.location = 'index.php';";
    echo "</script>";
}
?>
<?php
require_once "operacoesPHP/conection.php";

$ID = $_GET['ID'];

$sql = "SELECT * FROM SERVIDOR WHERE ID_SERVIDOR = $ID;";

$result = mysqli_query($con, $sql);

$linha = mysqli_fetch_assoc($result);

$NOME = $linha['NOME'];
$TIPO_SERVIDOR = $linha['TIPO_SERVIDOR'];
$DATA_NASCIMENTO = $linha['DATA_NASCIMENTO'];
$LATTES = $linha['LINK_LATTES'];
$FACEBOOK = $linha['FACEBOOK'];
$EMAIL = $linha['EMAIL'];
$LOGIN = $linha['LOGIN'];

if (($PERMISSAO == 3) || ($ID_LOGADO == $ID)) {
    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <script type="text/javascript">
                function voltar() {
                    window.location = 'visualizar_servidor.php';
                }
                </script>
            <link href="Styles/CSS.css" rel="stylesheet" type="text/css"/>
            <meta charset="UTF-8">
            <title>AGE - Alteração de Dados de Servidor</title>
        </head>
        <body style="background-color: #9cea70"  onload="startTime()">
            <?php include("./cabecalho.html") ?>

            <table id="SITE">
                <tr>
                    <td id="MENU" valign="top">
                        <?php include("./menuLateral.php") ?>
                    </td>
                    <td id="CONTEUDO">
                        <form action="operacoesPHP/alterarServidor.php?ID=<?php echo $ID; ?>" method="POST" enctype="multipart/form-data">
                            <h1> Alteração de Servidor </h1>
                            <table width="400" border="0">
                                <tr>
                                    <td>Foto Perfil</td>
                                    <td><input type="file" name="arquivo" id="Arquivo"></td>
                                </tr>
                                <tr>
                                    <td width="150px">Nome*:</td>
                                    <td><input type="text" name="NOME" value="<?php echo $NOME; ?>" required></td>
                                </tr>
                                <tr>
                                    <td>Nascimento*:</td>
                                    <td><input type="date" name="DATA_NASCIMENTO" value="<?php echo $DATA_NASCIMENTO; ?>" required></td>
                                </tr>
                                <tr>
                                    <td>E-mail*:</td>
                                    <td><input type="email" name="EMAIL" value="<?php echo $EMAIL; ?>" required></td>
                                </tr>
                                <tr>
                                    <td>Tipo Servidor*:</td>
                                    <td><input type="text" name="TIPO_SERVIDOR" value="<?php echo $TIPO_SERVIDOR; ?>" required></td>
                                </tr>
                                <tr>
                                    <td>Facebook(Link):</td>
                                    <td><input type="url" value="<?php echo $FACEBOOK; ?>" name="FACEBOOK"></td>
                                </tr>
                                <tr>
                                    <td>Lattes(Link):</td>
                                    <td><input type="url" value="<?php echo $LATTES; ?>" name="LATTES"></td>
                                </tr>
                                <tr>
                                    <td>Login*:</td>
                                    <td><input type="text" name="LOGIN" value="<?php echo $LOGIN; ?>" disabled required></td>
                                </tr>
                                <tr>
                                    <td><input type="submit" value="Alterar"></td>
                                    <td>
                                        <table style="width: 100%;">
                                            <tr>
                                                <td>
                                                    <input type="reset" value="Refefinir">
                                                </td>
                                                <td>
                                                    <input type="button" value="Voltar" onclick="return voltar()">
                                                </td>
                                            </tr>
                                        </table>
                                    </td>

                                </tr>
                            </table>
                            <div style="color: red; font-size: 14px;">*Caso deseje alterar senha, clique <a href="alterar_senha_servidor.php?ID=<?php echo $ID; ?>">aqui</a> por favor*</div>
                        </form>
                    </td>
                </tr>
            </table>
        </body>
    </html>
    <?php
}
?>